package com.yanqu.road.server.cmd.cross.marriage;

import com.yanqu.road.entity.marriage.CrossMarriageResult;
import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = Protocol.S_CROSS_MARRIAGE_TO_PARTNER_DEAL_AGREE, desc = "到对方服务器处理同意联姻")
public class CrossMarriageToPartnerDealAgreeCmd implements Command {
	@Override
	public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
		CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg reqMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealReqMsg.parseFrom(packet.getBytes());
		MarriageInfo marriageInfo = MarriagePb.parseMarriageInfo(reqMsg.getApplyData());
		String partnerChildUid = reqMsg.getPartnerChildUid();
		long partnerUserId = packet.getPlayerId();
		CrossMarriageResult marriageResult = MarriageMgr.toPartnerDealAgree(marriageInfo, partnerUserId, partnerChildUid);
		CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.Builder respMsg = CrossMarriageProto.CrossMarriageAgreeCrossDealRespMsg.newBuilder();
		respMsg.setRet(marriageResult.getRet());
		respMsg.setApplyData(MarriagePb.parseMarriageApplyTempMsg(marriageInfo));
		if(0 == marriageResult.getRet()){
			respMsg.setPartnerData(MarriagePb.parseMarriageApplyTempMsg(marriageResult.getMarriageInfo()));
		}
		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_AGREE_MARRIAGE_TO_PARTNER_DEAL_RESP, respMsg);
		GamePlayerMgr.sendPacket(0, pbMsg);
	}
}
